package com.ygqh.baby.service.impl;
import java.util.List;

import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.YgStyle;
import  com.ygqh.baby.mapper.YgStyleMapper;
import  com.ygqh.baby.service.YgStyleService;

import  org.springframework.util.Assert;
import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.YgStyleExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class YgStyleServiceImpl implements YgStyleService{
	
	@Autowired
	private YgStyleMapper ygStyleMapper;
	
	@Override
	public List<YgStyle> find() {
		YgStyleExample example = new YgStyleExample();
		example.createCriteria().andStatusNotEqualTo(DataStatus.Delete.name());
		return ygStyleMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		YgStyleExample example = new YgStyleExample();
		example.createCriteria().andStatusNotEqualTo(DataStatus.Delete.name());
		return ygStyleMapper.countByExample(example);
	}

	@Override
	public YgStyle findById(Long id) {
		return ygStyleMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(YgStyle ygStyle) {
		return ygStyleMapper.insertSelective(ygStyle);
	}

	@Override
	public int update(YgStyle ygStyle) {
		return ygStyleMapper.updateByPrimaryKeySelective(ygStyle);
	}

	@Override
	public ResultSet<YgStyle> search(QueryInfo queryInfo,Long supplierId,String q) {
		List<YgStyle>  list =  ygStyleMapper.selectSuper(supplierId,queryInfo, q);
		int count = ygStyleMapper.countSuper(supplierId,q);
		ResultSet<YgStyle> resultSet = new ResultSet<YgStyle>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		int count = 0;
		for(Long id:ids) {
			 YgStyle ygStyle =  this.findById(id);
			 ygStyle.setStatus(DataStatus.Delete);
			 count += ygStyleMapper.updateByPrimaryKeySelective(ygStyle);
		}
		
		return count;
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(YgStyle ygStyle) {
		int r = 0;
		if(ygStyle.getId() != null) {
			r = this.update(ygStyle);
		}else {
			r = this.save(ygStyle);
		}
		return r;
	}

}

